import requests

from bs4 import BeautifulSoup

url='https://movie.douban.com/top250?start='
headers={
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'
}




# list=[]
for i in range(0,10):
    baseurl=url+str(i*25)
    r = requests.get(baseurl, headers=headers)
    soup = BeautifulSoup(r.content.decode(), 'lxml')
    r1 = soup.find_all('div', {'class': 'info'})
    for e in r1:
        h={}
        h['电影']=e.find('div',{'class':'hd'}).select('span')[0].string
        h['评分']=e.find('div',{'class':'star'}).select('span')[1].string
        h['链接']=e.find('div',{'class':'hd'}).find('a')['href']
        with open('data.txt','a',encoding='utf-8') as f:
            f.write(h.__str__()+'\n')